import pyflag.Reports as Reports
import pyflag.DB as DB
import pyflag.FlagFramework as FlagFramework
from pyflag.ColumnTypes import InodeIDType, FilenameType 

class FilenameBrowseType(FilenameType):
    def __init__(self,selectstr,case,table='file'):
        FilenameType.__init__(self,case=case)
        self.table=table
        self.selectstr = selectstr
        self.case=case
        
        
        
    def where(self):
        return 'file.name like "%(pattern)s"'%{'pattern':self.selectstr}

class FindFile(Reports.report):
    """Finding files in scanned filesystem"""
    parameters = {"pattern":"string"}
    name = 'Find File'
    family = 'Disk Forensics'
    hidden = False
    selectstr=""

    def form(self,query,result):
        result.textfield("Enter pattern",'pattern')
        result.case_selector()

    def display(self,query,result):
        dbh=self.DBO(query['case'])
        try:
            result.table(
                elements = [InodeIDType(),
                            FilenameBrowseType(query['pattern'],case=query['case'])],
                case=query['case'],
                table="file"
                )
        except DB.DBError,e:
            result.para("Error")
            result.para("Error reported was:")
            result.text(e,style="red")
